package leetcode.easy.q66;

public class Q {
}
class Solution {
    public int[] plusOne(int[] digits) {
        int[] result = digits;
        int sum = 0;
        for (int i = digits.length - 1; i >= 0; i--) {
            sum = digits[i] + 1;
            digits[i] = sum % 10;
            if (sum <= 9) {
                break;
            }
        }
        if (sum > 9) {
            result = new int[digits.length + 1];
            cpOld(result, digits);
            result[0] = 1;
        }
        return result;
    }

    private void cpOld(int[] goal, int[] source) {
        for (int i = 1; i < goal.length; i++) {
            goal[i] = source[i-1];
        }
    }
}